import time

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By

path = Service('./chromedriver')
# 打开浏览器，返回浏览器对象
driver = webdriver.Chrome(service=path)
# 打开必应首页
driver.get('https://cn.bing.com/')
# 等待2s
time.sleep(2)
# 通过id定位元素
search_box_id = driver.find_element(By.ID, 'video')
# 通过class name定位元素，class="scope try_exp"
search_box_class_name = driver.find_elements(By.CLASS_NAME, 'try_exp')
# 通过超链接的文本值定位元素
video_link_text = driver.find_element(By.LINK_TEXT, '视频')
# 通过超链接的部分文本值定位元素
video_patrial_link_text = driver.find_element(By.PARTIAL_LINK_TEXT, '频')
# 通过xpath定位
video_xpath = driver.find_element(By.XPATH, '//*[@id="video"]/a')
# 通过css定位
video_css_selector = driver.find_element(By.CSS_SELECTOR, '#video > a')

print(search_box_id)
print(search_box_class_name[0])
print(video_link_text)
print(video_patrial_link_text)
print(video_xpath)
print(video_css_selector)

# <span class="tob_title">琼瑶留10亿巨额版权</span>

# 关闭浏览器
driver.quit()
